package forum.communication;

import forum.server.controller.ForumFacadeInt;
import forum.server.exceptions.InvalidSearchRangeException;
import forum.server.exceptions.NoSuchUserException;

public class SearchByAuthorMessage extends ClientMessage {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5922424051854556092L;
	
	private String username;
	private int from;
	private int to;
	
	public SearchByAuthorMessage(String username, int from, int to) {
		this.username = username;
		this.from = from;
		this.to = to;
	}
	
	@Override
	public ServerResponse doOperation(ForumFacadeInt forum) {
		try {
			return new ServerResponse(forum.searchByAuthor(username, from, to),true);
		} catch (NoSuchUserException e) {
			return new ServerResponse(e.getMessage(), false);
		} catch (InvalidSearchRangeException e) {
			return new ServerResponse(e.getMessage(), false);
		}
	}

}
